package com.example.yunifangdemo.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import com.example.yunifangdemo.MainActivity;
import com.example.yunifangdemo.R;

public class SplashActivity extends AppCompatActivity {

    private boolean isFirstIn;//是否第一次登陆
    private SharedPreferences preferences;

    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            //接收消息并跳转
            if (msg.what == 1){
                if (isFirstIn){
                    Intent intent = new Intent(SplashActivity.this,MainActivity.class);
                    startActivity(intent);
                    finish();
                }else{
                    Intent intent = new Intent(SplashActivity.this,GuideActivity.class);
                    startActivity(intent);
                    finish();
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putBoolean("isFirshIn",true);
                    editor.commit();
                }

            }
        }
    };



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 无标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 全屏显示
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash);
        preferences = getSharedPreferences("first_fref",MODE_PRIVATE);
        isFirstIn = preferences.getBoolean("isFirshIn",false);
        //发送延迟2秒的消息
        handler.sendEmptyMessageDelayed(1,2000);
    }
}
